package no.hig.ekm.ircclient;

import java.awt.Cursor;
import java.util.ResourceBundle;
import java.beans.PropertyVetoException;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JToolBar;

/**
 * Creates a new toolbar with buttons
 * 
 * @author Kristofers
 */
@SuppressWarnings("serial")
public class MainToolbar extends JToolBar {
	private static ResourceBundle messages;
	
	JButton btnConnect = new JButton();
	public static ConnectionDialog cd = null;
	IniParser ip = new IniParser();

	/**
	 * Default constructor for generating toolbar
	 */
	public MainToolbar() {
		btnConnect.setIcon(new ImageIcon(getClass().getResource(
				"icons/connect.gif")));
		btnConnect.setToolTipText(messages.getString("mainToolbarConnectbtnTooltip"));

		// Open/bring to front the ConnectionDialog window
		btnConnect.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				if ((cd == null) || !cd.isVisible()) {
					setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
					cd = new ConnectionDialog();
					MainWindow.md.add(cd);
					ConnectionDialog.setNetworkList(IniParser.nets);
					setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
				}
				cd.toFront();
				try {
					cd.setSelected(true);
				} catch (PropertyVetoException e) {
					e.printStackTrace();
				}
			}
		});
		add(btnConnect);
	}
	
	/**
	 * Sets the ResourceBundle used for internationalization.
	 * 
	 * @param m - ResourceBundle
	 */
	public static void setMessages(ResourceBundle m){
		messages = m;
	}

}
